@echo off
@REM  ----------------------------------------------------------------------------
@REM  CopyAssemblies.bat file
@REM
@REM  This batch file copies the Enterprise Library Contrib assemblies from their build
@REM  location to a common destination folder.
@REM  
@REM  Optional arguments for this batch file:
@REM   1 - The build output folder (Release, Debug, etc. Defaults to Debug)
@REM   2 - The destination folder (i.e. where the build will be dropped.
@REM       Defaults to ..\bin)
@REM  
@REM  ----------------------------------------------------------------------------

echo.
echo ===============================================================
echo   CopyAssemblies                                         
echo      Copies Enterprise Library Contrib assemblies to a single    
echo      destination directory                              
echo ===============================================================
echo.

set solutionDir="..\Blocks"
set buildType=Debug
set binDir="..\bin"
set pause=true

if "%1"=="/?" goto HELP

if not Exist %solutionDir%\EnterpriseLibrary.sln goto HELP

@REM  ----------------------------------------------------
@REM  If the first parameter is /q, do not pause
@REM  at the end of execution.
@REM  ----------------------------------------------------

if /i "%1"=="/q" (
 set pause=false
 SHIFT
)

@REM  ------------------------------------------------------
@REM  User can override default build type by specifiying
@REM  a parameter to batch file (e.g. CopyAssemblies Release).
@REM  ------------------------------------------------------

if not "%1"=="" set buildType=%1

@REM  ---------------------------------------------------------------
@REM  User can override default destination directory by specifiying
@REM  a parameter to batch file (e.g. CopyAssemblies Debug c:\bin).
@REM  ---------------------------------------------------------------

if not "%2"=="" set binDir=%2

@REM  ----------------------------------------
@REM  Shorten the command prompt for output
@REM  ----------------------------------------
set savedPrompt=%prompt%
set prompt=*$g


@ECHO ----------------------------------------
@ECHO CopyAssemblies.bat Started
@ECHO ----------------------------------------
@ECHO.

@REM -------------------------------------------------------
@REM Change to the directory where the solution file resides
@REM -------------------------------------------------------

pushd %solutionDir%

@ECHO.
@ECHO ----------------------------------------
@ECHO Create destination folder 
@ECHO ----------------------------------------
@ECHO.

if not Exist %binDir% mkdir %binDir%

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy referenced binary files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Lib\IBM.Data.DB2.dll copy /V ..\Lib\IBM.Data.DB2.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\IBM.Data.DB2.Entity.dll copy /V ..\Lib\IBM.Data.DB2.Entity.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\IBM.Data.Informix.dll copy /V ..\Lib\IBM.Data.Informix.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\IBM.Data.U2.Ucinet.dll copy /V ..\Lib\IBM.Data.U2.Ucinet.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\Mono.Security.dll copy /V ..\Lib\Mono.Security.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\MySql.Data.CF.dll copy /V ..\Lib\MySql.Data.CF.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\MySql.Data.dll copy /V ..\Lib\MySql.Data.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\MySql.Data.Entity.dll copy /V ..\Lib\MySql.Data.Entity.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\MySql.Web.dll copy /V ..\Lib\MySql.Web.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\Npgsql.dll copy /V ..\Lib\Npgsql.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\policy.2.0.Npgsql.dll copy /V ..\Lib\policy.2.0.Npgsql.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\Oracle.DataAccess.dll copy /V ..\Lib\Oracle.DataAccess.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\System.Data.SQLite.dll copy /V ..\Lib\System.Data.SQLite.dll %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Lib\System.Data.SQLite.Linq.dll copy /V ..\Lib\System.Data.SQLite.Linq.dll %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Common files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Common\Src\Common\bin\%buildType%\EntLibContrib.Common.dll copy /V ..\Blocks\Common\Src\Common\bin\%buildType%\EntLibContrib.Common.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Common\Src\Common\bin\%buildType%\EntLibContrib.Common.xml copy /V ..\Blocks\Common\Src\Common\bin\%buildType%\EntLibContrib.Common.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Common\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Common.Configuration.Design.dll copy /V ..\Blocks\Common\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Common.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Common\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Common.Configuration.Design.xml copy /V ..\Blocks\Common\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Common.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Data Access files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Data\Src\DB2\bin\%buildType%\EntLibContrib.Data.DB2.dll copy /V ..\Blocks\Data\Src\DB2\bin\%buildType%\EntLibContrib.Data.DB2.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\DB2\bin\%buildType%\EntLibContrib.Data.DB2.xml copy /V ..\Blocks\Data\Src\DB2\bin\%buildType%\EntLibContrib.Data.DB2.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Data\Src\MySql\bin\%buildType%\EntLibContrib.Data.MySql.dll copy /V ..\Blocks\Data\Src\MySql\bin\%buildType%\EntLibContrib.Data.MySql.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\MySql\bin\%buildType%\EntLibContrib.Data.MySql.xml copy /V ..\Blocks\Data\Src\MySql\bin\%buildType%\EntLibContrib.Data.MySql.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Data\Src\OdpNet\bin\%buildType%\EntLibContrib.Data.OdpNet.dll copy /V ..\Blocks\Data\Src\OdpNet\bin\%buildType%\EntLibContrib.Data.OdpNet.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\OdpNet\bin\%buildType%\EntLibContrib.Data.OdpNet.xml copy /V ..\Blocks\Data\Src\OdpNet\bin\%buildType%\EntLibContrib.Data.OdpNet.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Data\Src\PostgreSql\bin\%buildType%\EntLibContrib.Data.PostgreSql.dll copy /V ..\Blocks\Data\Src\PostgreSql\bin\%buildType%\EntLibContrib.Data.PostgreSql.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\PostgreSql\bin\%buildType%\EntLibContrib.Data.PostgreSql.xml copy /V ..\Blocks\Data\Src\PostgreSql\bin\%buildType%\EntLibContrib.Data.PostgreSql.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Data\Src\SqlEx\bin\%buildType%\EntLibContrib.Data.SqlEx.dll copy /V ..\Blocks\Data\Src\SqlEx\bin\%buildType%\EntLibContrib.Data.SqlEx.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\SqlEx\bin\%buildType%\EntLibContrib.Data.SqlEx.xml copy /V ..\Blocks\Data\Src\SqlEx\bin\%buildType%\EntLibContrib.Data.SqlEx.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Data\Src\SQLite\bin\%buildType%\EntLibContrib.Data.SQLite.dll copy /V ..\Blocks\Data\Src\SQLite\bin\%buildType%\EntLibContrib.Data.SQLite.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Data\Src\SQLite\bin\%buildType%\EntLibContrib.Data.SQLite.xml copy /V ..\Blocks\Data\Src\SQLite\bin\%buildType%\EntLibContrib.Data.SQLite.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Exception Handling files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\ExceptionHandling\Src\ExceptionHandling\bin\%buildType%\EntLibContrib.ExceptionHandling.dll copy /V ..\Blocks\ExceptionHandling\Src\ExceptionHandling\bin\%buildType%\EntLibContrib.ExceptionHandling.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\ExceptionHandling\Src\ExceptionHandling\bin\%buildType%\EntLibContrib.ExceptionHandling.xml copy /V ..\Blocks\ExceptionHandling\Src\ExceptionHandling\bin\%buildType%\EntLibContrib.ExceptionHandling.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\ExceptionHandling\Src\Configuration.Design\bin\%buildType%\EntLibContrib.ExceptionHandling.Configuration.Design.dll copy /V ..\Blocks\ExceptionHandling\Src\Configuration.Design\bin\%buildType%\EntLibContrib.ExceptionHandling.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\ExceptionHandling\Src\Configuration.Design\bin\%buildType%\EntLibContrib.ExceptionHandling.Configuration.Design.xml copy /V ..\Blocks\ExceptionHandling\Src\Configuration.Design\bin\%buildType%\EntLibContrib.ExceptionHandling.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Logging files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Logging\Src\Logging\bin\%buildType%\EntLibContrib.Logging.dll copy /V ..\Blocks\Logging\Src\Logging\bin\%buildType%\EntLibContrib.Logging.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Logging\Src\Logging\bin\%buildType%\EntLibContrib.Logging.xml copy /V ..\Blocks\Logging\Src\Logging\bin\%buildType%\EntLibContrib.Logging.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Policy Injection files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\PolicyInjection\Src\PolicyInjection.CallHandlers\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.dll copy /V ..\Blocks\PolicyInjection\Src\PolicyInjection.CallHandlers\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\PolicyInjection\Src\PolicyInjection.CallHandlers\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.xml copy /V ..\Blocks\PolicyInjection\Src\PolicyInjection.CallHandlers\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\PolicyInjection\Src\CallHandlers.Configuration.Design\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design.dll copy /V ..\Blocks\PolicyInjection\Src\CallHandlers.Configuration.Design\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\PolicyInjection\Src\CallHandlers.Configuration.Design\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design.xml copy /V ..\Blocks\PolicyInjection\Src\CallHandlers.Configuration.Design\bin\%buildType%\EntLibContrib.PolicyInjection.CallHandlers.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Query files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Query\Src\Query\bin\%buildType%\EntLibContrib.Query.dll copy /V ..\Blocks\Query\Src\Query\bin\%buildType%\EntLibContrib.Query.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Query\Src\Query\bin\%buildType%\EntLibContrib.Query.xml copy /V ..\Blocks\Query\Src\Query\bin\%buildType%\EntLibContrib.Query.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Query\Src\Database\bin\%buildType%\EntLibContrib.Query.Database.dll copy /V ..\Blocks\Query\Src\Database\bin\%buildType%\EntLibContrib.Query.Database.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Query\Src\Database\bin\%buildType%\EntLibContrib.Query.Database.xml copy /V ..\Blocks\Query\Src\Database\bin\%buildType%\EntLibContrib.Query.Database.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Query\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Query.Configuration.Design.dll copy /V ..\Blocks\Query\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Query.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Query\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Query.Configuration.Design.xml copy /V ..\Blocks\Query\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Query.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Query\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Query.Database.Configuration.Design.dll copy /V ..\Blocks\Query\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Query.Database.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Query\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Query.Database.Configuration.Design.xml copy /V ..\Blocks\Query\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Query.Database.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Resource files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Resource\Src\Resource\bin\%buildType%\EntLibContrib.Resource.dll copy /V ..\Blocks\Resource\Src\Resource\bin\%buildType%\EntLibContrib.Resource.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Resource\Src\Resource\bin\%buildType%\EntLibContrib.Resource.xml copy /V ..\Blocks\Resource\Src\Resource\bin\%buildType%\EntLibContrib.Resource.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Resource\Src\Database\bin\%buildType%\EntLibContrib.Resource.Database.dll copy /V ..\Blocks\Resource\Src\Database\bin\%buildType%\EntLibContrib.Resource.Database.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Resource\Src\Database\bin\%buildType%\EntLibContrib.Resource.Database.xml copy /V ..\Blocks\Resource\Src\Database\bin\%buildType%\EntLibContrib.Resource.Database.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Resource\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Configuration.Design.dll copy /V ..\Blocks\Resource\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Resource\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Configuration.Design.xml copy /V ..\Blocks\Resource\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Resource\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Database.Configuration.Design.dll copy /V ..\Blocks\Resource\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Database.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Resource\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Database.Configuration.Design.xml copy /V ..\Blocks\Resource\Src\Database.Configuration.Design\bin\%buildType%\EntLibContrib.Resource.Database.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO Copy Validation files with verification
@ECHO ----------------------------------------
@ECHO.

if Exist ..\Blocks\Validation\Src\Validation\bin\%buildType%\EntLibContrib.Validation.dll copy /V ..\Blocks\Validation\Src\Validation\bin\%buildType%\EntLibContrib.Validation.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Validation\Src\Validation\bin\%buildType%\EntLibContrib.Validation.xml copy /V ..\Blocks\Validation\Src\Validation\bin\%buildType%\EntLibContrib.Validation.xml %binDir%\.
@if errorlevel 1 goto :error

if Exist ..\Blocks\Validation\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Validation.Configuration.Design.dll copy /V ..\Blocks\Validation\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Validation.Configuration.Design.dll %binDir%\.
@if errorlevel 1 goto :error
if Exist ..\Blocks\Validation\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Validation.Configuration.Design.xml copy /V ..\Blocks\Validation\Src\Configuration.Design\bin\%buildType%\EntLibContrib.Validation.Configuration.Design.xml %binDir%\.
@if errorlevel 1 goto :error

@ECHO.
@ECHO ----------------------------------------
@ECHO CopyAssemblies.bat Completed
@ECHO ----------------------------------------
@ECHO.

@REM  ----------------------------------------
@REM  Restore the command prompt and exit
@REM  ----------------------------------------
@goto :exit

@REM  -------------------------------------------
@REM  Handle errors
@REM
@REM  Use the following after any call to exit
@REM  and return an error code when errors occur
@REM
@REM  if errorlevel 1 goto :error	
@REM  -------------------------------------------
:error
  @ECHO An error occured in CopyAssemblies.bat - %errorLevel%

if %pause%==true PAUSE
@exit errorLevel

:HELP
echo Usage: CopyAssemblies [/q] [build output folder] [destination dir]
echo.
echo CopyAssemblies is to be executed in the directory where EnterpriseLibrary.sln resides
echo The default build output folder is Debug
echo The default destintation directory is bin
echo.
echo Examples:
echo.
echo    "CopyAssemblies" - copies Debug build assemblies to bin      
echo    "CopyAssemblies Release" - copies Release build assemblies to bin
echo    "CopyAssemblies Release C:\temp" - copies Release build assemblies to C:\temp
echo.

@REM  ----------------------------------------
@REM  The exit label
@REM  ----------------------------------------
:exit
popd
set pause=
set solutionDir=
set buildType=
set prompt=%savedPrompt%
set savedPrompt=
echo on